export default class BodyAction{
    constructor(comp){
        this.comp = comp
    }


    pageSizeSelect =async(val)=>{
        const {props} = this.comp
        const {main,dispatch} = props
        let pageInfo = main.pageInfo
        pageInfo.pageSize = val;
        pageInfo.pageIndex = 0;
        await dispatch({
            type : 'main/update',
            payload: {
                pageInfo : pageInfo,
                focusIndex: 0
            }
        })
        if(main.widget){
            this.pubSub.publish('getWidgetTableData', {
                pageInfo:pageInfo
           });
        }else{
            this.pubSub.publish('queryTableData', {
                // pageInfo: {pageIndex:main.pageInfo.pageIndex,pageSize:val}
                pageInfo:pageInfo
            });
        }
    }

    paginationEve =async(key)=>{
        const {props} = this.comp
        const {main,dispatch} = props
        let pageInfo = main.pageInfo
        pageInfo.pageIndex = key;
        await dispatch({
            type: 'main/update',
            payload: {
                pageInfo: pageInfo,
                focusIndex: 0
            }
        })
        if(main.widget){
            this.pubSub.publish('getWidgetTableData', {
                pageInfo:pageInfo
           });
        }else{
            this.pubSub.publish('queryTableData', {
                // pageInfo: {pageIndex:main.pageInfo.pageIndex,pageSize:val}
                pageInfo:pageInfo
            });
        }
    }

    onRowClick =(props, moduleId, record, index,e)=>{
        const {dispatch} = props
        if(moduleId === 'list'){
            dispatch({
                type: 'main/update',
                payload: {
                    focusIndex: index
                }
            })
        }

    }

    onRowDoubleClick =(record,index,props,e)=>{
        const {main,button,meta} = props
        let billid =   record.values.pk_hi_stapply.value
        let data ={
            pk_org: main.orgvalue.refpk,
            billid: billid
        }
        console.log(meta.getMeta())
        this.queryDataDetail(data)
    }  

    queryDataDetail =(data)=>{
        const {props} = this.comp
        const {dispatch,button,main} = props
        dispatch({
            type: 'main/queryDataDetail',
            payload: data
        }).then((res)=>{
            if(res.data){
                if(res.data.card){
                    props.form.setAllFormValue({'card':res.data.card.card})
                }else{
                    props.form.setAllFormValue({'card': {rows:[]}})
                }
                if(res.data.handover){
                    props.editTable.setTableData('handover',res.data.handover.handover)
                }else{
                    props.editTable.setTableData('handover',{rows:[]})
                }
            }
                button.setButtonVisible({
                    'query': false,
                    'confirm': true,
                    'print': true,
                    'printjjd': true,
                    'printzm': true
                })
            dispatch({
                type: 'main/update',
                payload: {
                    showPage: 'card',
                    showChangePage: true
                }
            })
            props.cardPagination.getNextCardPaginationId({ id: data.billid, status: 1 });
            props.cardPagination.setCardPaginationId({ id: data.billid, status: 1 });
        })
    }
}